package com.baizw.cultivation.module.admin.controller;

import cn.hutool.core.collection.CollUtil;
import com.baizw.cultivation.common.response.ResultBean;
import com.baizw.cultivation.common.response.ResultPage;
import com.baizw.cultivation.module.admin.entity.NoticeEntity;
import com.baizw.cultivation.module.admin.page.NoticeSearch;
import com.baizw.cultivation.module.admin.service.NoticeService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 公告管理
 *
 * @author 剧终1204
 * @version V1.0
 * @date 2020年07月27日 16:21
 */
@RestController
@Api(tags = "字典管理")
@RequestMapping("/api/notice")
public class NoticeController {

    @Autowired
    private NoticeService noticeService;


    @PostMapping("/page")
    @ApiOperation("分页查询通知/公告数据")
    public ResultPage typeListPage(@RequestBody NoticeSearch search) {
        IPage<NoticeEntity> dataSearch = noticeService.pageByParams(search);
        return ResultPage.success(dataSearch);
    }

    @ApiOperation("获取通知/公告详情")
    @GetMapping("/detail/{id}")
    public ResultBean dictTypeDetail(@PathVariable Long id) {
        NoticeEntity noticeEntity = noticeService.getById(id);
        return ResultBean.ok(noticeEntity);
    }

    /**
     * 新增通知/公告
     */
    @ApiOperation("新增通知/公告")
    @PostMapping("/insert")
    public ResultBean add(@Validated @RequestBody NoticeEntity dict) {
        return ResultBean.ok(noticeService.save(dict));
    }

    /**
     * 修改通知/公告
     */
    @ApiOperation("修改通知/公告")
    @PutMapping("/update")
    public ResultBean edit(@Validated @RequestBody NoticeEntity dict) {
        return ResultBean.ok(noticeService.updateById(dict));
    }

    /**
     * 删除通知/公告
     */
    @ApiOperation("删除通知/公告")
    @DeleteMapping("/remove/{dictIds}")
    public ResultBean remove(@PathVariable Long[] dictIds) {
        return ResultBean.ok(noticeService.removeByIds(CollUtil.toList(dictIds)));
    }
}
